<?php
//**************************************************************************************************
//==================================================================================================
//**************************************************************************************************
function form_load($msg = "", $tipo = "") {
	global $form_name;
	$txtNome = "";
	echo "<h4>" . montaLink (_MI_MP3PLAYER_NAME, METODO_PADRAO, FORM_PADRAO) . " :: " . montaLink (_MI_MP3PLAYER_MENU2) . "</h4>";
	if ($msg != '') {
		if ($tipo == "S") { //sucesso		
			xoops_result($msg, _MI_MP3PLAYER_CAPTION_MSG_SUCESS);
			unset($_POST);
		} else if ($tipo == "E") { //erro
			xoops_error($msg, _MI_MP3PLAYER_CAPTION_MSG_ERR_);
			$txtNome = $_POST['txtNome'];
		}
	}
	include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';		
	$form = new XoopsThemeForm(_MI_MP3PLAYER_MENU2, $form_name . '_form', 'index.php', "post", true);
	$form->addElement(new XoopsFormHidden(FORM_PARAM, $form_name));
	$form->addElement(new XoopsFormHidden(FUNCTION_PARAM, 'exec'));
	//==================================================================================
	$form->addElement(new XoopsFormText(_MI_MP3PLAYER_NOME_PLAYLIST, 'txtNome', 30, 30, $txtNome), true);	
	//==================================================================================	
	$form->addElement(new XoopsFormButton('', $form_name . '_submit', _SUBMIT, 'submit'));	
	$form->display();
	//==================================================================================	
	echo "<table width='100%' border='0' cellspacing='3' class='outer'>";
	echo "<tr class=\"odd\">";
	$playlist_handler =& xoops_getmodulehandler('mp3player_playlist');	
	$criteria = new Criteria();
	$criteria->setSort('id');
	$criteria->setOrder('DESC');	
	$playlists =& $playlist_handler->getObjects($criteria);
	$contador = 0;
	foreach ($playlists as &$playlist) {
        if ($contador % 6 == 0) {echo '</tr><tr class=\"odd\">';}
		echo '<td><a href="'.XOOPS_URL.'/modules/mp3player/admin/index.php?frm=criarplaylist&act=edit&id='.$playlist->getVar('id').'">'.$playlist->getVar('nome').'</a></td>';
		$contador++;
	}
	unset($playlist_handler);
	echo '</tr>';	
	echo '</table>';	
}

function form_exec() {
	$msg="";
	$tipo="E";//erro		
    if (!$GLOBALS['xoopsSecurity']->check()) {
        $msg = $GLOBALS['xoopsSecurity']->getErrors();
    } else if (form_insert($_POST['txtNome'])) {
		$msg  = _MI_MP3PLAYER_PLAYLIST_SUCESS;
		$tipo = "S";//sucess
	} else {
		$msg = _MI_MP3PLAYER_ERR_SQL_INSERT_PLAYLIST;
	}
	form_load($msg, $tipo);
}
function form_insert($nome) {
	$playlist_handler =& xoops_getmodulehandler('mp3player_playlist');
	$playlist =& $playlist_handler->create();
	$playlist->setVar('nome', $nome);
	$playlist->setVar('dt_alteracao', date('Y-m-d H:i:s'));
	$retorno = $playlist_handler->insert($playlist);
	unset($playlist_handler);
	return $retorno;
}
function form_edit() {
echo $_GET['id'];
}
//**************************************************************************************************
//==================================================================================================
//**************************************************************************************************
?>